﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation;
using Micrhard.FMCG.Server.Models;
using Micrhard.FMCG.Server.Msg;
using Micrhard.FMCG.Server.Interface;
using Microhard.Core;
using FluentValidation.Results;

namespace Micrhard.FMCG.Server.Validator
{
  public  class IspCategoryModelValidator : AbstractValidator<IspCategoryModel>
    {
      public IspCategoryModelValidator()
        {
            RuleSet("Insert", () =>
            {
                RuleFor(u => u.Name).NotEmpty().WithMessage(IspCategoryMsg.NeedName).When(r => r.CheckListCategoryID == Guid.Empty);
                RuleFor(u => u.Name).Length(1, 50).WithMessage(IspCategoryMsg.MaxNameLength).When(r => r.CheckListCategoryID == Guid.Empty);
                Custom(u =>
                {
                    IIspCategory iclt = IoC.Resolve<IIspCategory>();
                    if (iclt.IsNameDuplicate(u))
                    {
                        return new ValidationFailure("Name", IspCategoryMsg.DuplicateName);
                    }
                    return null;
                });
            });
        }
    }
}
